<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport"
    content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  <meta name="author" content="火星科技 http://mars2d.cn " />
  <meta name="apple-touch-fullscreen" content="yes" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  <meta name="format-detection" content="telephone=no" />
  <meta name="x5-fullscreen" content="true" />
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
  <!-- 标题及搜索关键字 -->
  <meta name="keywords" content="火星科技,cesium,2D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
  <meta name="description"
    content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS" />

  <link rel="shortcut icon" type="image/x-icon" href="img/favicon/favicon.ico" />
  <title>ArcGIS Server矢量服务查询 | Mars2d | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>

  <!--第三方lib-->
  <script type="text/javascript" src="/lib/include-lib.js" libpath="/lib/"
    include="jquery,font-awesome,web-icons,turf,bootstrap,bootstrap-table,bootstrap-checkbox,layer,toastr,haoutil,mars2d,echarts"></script>

  <link href="/css/style.css" rel="stylesheet" />
  <style>
    .querybar-page {
      margin: 10px 0 0 0;
      font-size: 12px;
    }

    .querybar-ye a {
      text-decoration: none;
      padding: 4px 6px;
      color: #000;
      border: solid 1px #000;
      margin-right: 4px;
    }

    .querybar-ye a:hover {
      color: #000;
      border-color: #dcdcdc;
    }

    .querybar-fl {
      float: left;
    }

    .querybar-fr {
      float: right;
    }

    .tab_list {
      height: 39x;
      /* border: 1px solid #ccc; */
    }

    .tab_list li {
      float: left;
      height: 39px;
      line-height: 39px;
      padding: 0 20px;
      text-align: center;
      cursor: pointer;
      list-style: none;
    }

    .tab_list .current {
      background-color: rgba(63, 72, 84, 0.7);
    }
  </style>
</head>

<body>


  <div id="mars2dContainer" class="mars2d-container"></div>

  <div class="infoview">
    <table class="mars-table" style="border-collapse:separate; border-spacing:0px 6px;">
      <tr>
        <td class="nametd">名称：</td>
        <td>
          <input id="queryText" type="text" placeholder="请输入查询关键字" value="" class="form-control" />
        </td>
      </tr>
      <tr>
        <td class="nametd">范围：</td>
        <td>
          <input type="button" class="btn btn-primary" value="框选范围" onclick="drawRectangle()" />
          <input type="button" class="btn btn-primary" value="圆形范围" onclick="drawCircle()" />
          <input type="button" class="btn btn-primary" value="多边形范围" onclick="drawPolygon()" />
        </td>
      </tr>
      <tr>
        <td class="nametd">范围：</td>
        <td>
          <input type="button" class="btn btn-primary" value="查询" id="query" />
          <input type="button" class="btn btn-primary" value="清除" id="clearAll" />
        </td>
      </tr>
    </table>

    <div class="tab" id="tab_check" style="display: none">
      <di1v class="tab_list">
        <ul>
          <li class="current">表格</li>
          <li>饼状图</li>
          <li>柱状图</li>
        </ul>
      </di1v>
      <div class="tab_con">
        <table id="table" class="item" style="max-height: 300px; min-height: 100px; display: block"></table>
        <div id="pieChart" class="item" style="width: 380px; height: 300px; display: none"></div>
        <div id="histogram" class="item" style="width: 380px; height: 300px; display: none"></div>
      </div>
    </div>
  </div>

  <script src="/js/common.js"></script>
  <script src="./map.js"></script>

  <script type="text/javascript">
    "use script" //开发环境建议开启严格模式

    eventTarget.on("loadOk", (event) => {
      const arrPie = [] // 饼状图:名称+面积
      const arrTable = [] // 表格: 名称+面积+数量
      const arrType = [] // 柱状图:名称
      const arrArea = [] // 柱状图:面积
      console.log(event, event.list)
      event?.list?.forEach((item, index) => {
        arrType.push(item.type)
        arrArea.push(item.area)
        arrPie.push({ name: item.type, value: item.area })
        arrTable.push({ key: index, index: index + 1, type: item.type, num: item.count, area: item.area })
      })
      showEcharts(arrTable, arrPie, arrArea, arrType)

      if (event.list) {
        $("#tab_check").show()
      }
    })

    //table栏切换Ui
    function initUI() {
      $("#query").click(function () {
        let queryVal = $.trim($("#queryText").val())
        queryData(queryVal)
      })

      $("#clearAll").click(function () {
        $("#tab_check").hide()
        clearAll()
      })

      let tab_list = document.querySelector(".tab_list")
      let lis = tab_list.querySelectorAll("li")
      let item = document.querySelectorAll(".item")

      for (let i = 0; i < lis.length; i++) {
        lis[i].setAttribute("index", i)
        lis[i].onclick = function () {
          for (let i = 0; i < lis.length; i++) {
            lis[i].className = ""
          }
          this.className = "current"
          let index = this.getAttribute("index")
          for (let j = 0; j < item.length; j++) {
            item[j].style.display = "none"
          }
          item[index].style.display = "block"
        }
      }
    }

    //统计面积数据并按表格图表来展示
    function showEcharts(arrTable, arrPie, arrArea, arrType) {
      //bootstratTable 表格
      $("#table").bootstrapTable("destroy")
      $("#table").bootstrapTable({
        data: arrTable,
        pagination: false,
        singleSelect: true,
        iconsPrefix: "fa",
        columns: [
          {
            title: "序号",
            sortable: true,
            editable: false,
            align: "center",
            formatter: function (value, row, index) {
              return index + 1
            }
          },
          {
            title: "类别",
            field: "name",
            align: "center",
            cellStyle: function (value, row, index) {
              return {
                css: {
                  width: "160px"
                }
              }
            }
          },
          {
            title: "数量",
            field: "count",
            align: "center"
          },
          {
            title: "面积(亩)",
            field: "area",
            align: "center"
          }
        ]
      })

      //echarts饼状图
      let pieEcharts = echarts.init(document.getElementById("pieChart"))
      let option = {
        title: {
          text: "饼状图",
          left: "center",
          textStyle: {
            color: "#000"
          }
        },
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} 亩</br>占比 : {d}%",
          backgroundColor: "rgba(63, 72, 84, 0.1)",
          textStyle: {
            color: "#000"
          }
        },
        series: [
          {
            name: "用地面积",
            type: "pie",
            radius: "50%",
            data: arrPie,
            textStyle: {
              color: "#000"
            },
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.2)"
              }
            }
          }
        ]
      }
      pieEcharts.setOption(option)

      //echarts柱状图
      let histogramECharts = echarts.init(document.getElementById("histogram"))
      let histogramOption = {
        tooltip: {
          trigger: "item",
          backgroundColor: "rgba(63, 72, 84, 0.7)",
          formatter: "{b}: {c} 亩",
          textStyle: {
            color: "#000"
          }
        },
        title: {
          text: "柱状图",
          left: "center",
          textStyle: {
            color: "#000"
          }
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true
        },
        xAxis: {
          type: "value",
          boundaryGap: [0, 0.01],
          show: false
        },
        yAxis: {
          type: "category",
          data: arrType,
          axisLabel: {
            textStyle: {
              color: " #000"
            }
          }
        },
        series: [
          {
            type: "bar",
            data: arrArea,
            itemStyle: {
              normal: {
                label: {
                  show: true,
                  position: "right",
                  textStyle: {
                    color: "#000"
                  }
                }
              }
            }
          }
        ]
      }
      histogramECharts.setOption(histogramOption)
    }
  </script>
</body>

</html>
